﻿/*去除字符串左右空格*/
String.prototype.trim = function () {
    return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

/*设置焦点，清空内容*/
function setFocus(userid, usermsg, pwdid, pwdmsg) {
    var user = document.getElementById(userid);
    var pwd = document.getElementById(pwdid);
    var lblUserMsg = document.getElementById(usermsg);
    lblUserMsg.style.display = "none";
    lblUserMsg.style.color = "red";
    var lblPwdMsg = document.getElementById(pwdmsg);
    lblPwdMsg.style.display = "none";
    lblPwdMsg.style.color = "red";
    user.value = "";
    pwd.value = "";
    user.focus();
}

/*重置功能*/
function setAll(arrs, focusID) {
    for (var i = 0; i < arrs.length; i++) {
        var t = document.getElementById(arrs[i]);
        {
            if (t.tagName.toUpperCase() == "INPUT") {
                t.value = "";
            } else if (t.tagName.toUpperCase() == "LABEL" || t.tagName.toUpperCase() == "SPAN") {
                t.style.display = "none";
            }
        }
    }
    document.getElementById(focusID).focus();
}

/*验证登陆信息是否完整*/
function checkInfo(userid, usermsg, pwdid, pwdmsg) {
    var userid = document.getElementById(userid);
    var pwd = document.getElementById(pwdid);
    var lbl = null;
    var ret = true;
    if (userid.value.trim() == "") {
        lbl = document.getElementById(usermsg);
        lbl.style.display = "inline-block";
        userid.value = "";
        userid.focus();
        ret = false;
    }
    if (pwd.value == "") {
        lbl = document.getElementById(pwdmsg);
        lbl.style.display = "inline-block";
        pwd.value = "";
        if (ret == true) {
            pwd.focus();
            ret = false;
        }
    }
    return ret;
}

/*清空对应控件文本*/
function clearMsg(id1, id2) {
    var obj = document.getElementById(id1);
    var em = false;
    if (obj.type == "text" && obj.value.trim() == "") {
        em = true;
    } else if (obj.type == "password" && obj.value == "") {
        em = true;
    }
    var obj2 = document.getElementById(id2);
    if (em) {
        obj2.style.display = "inline-block";
    } else {
        obj2.style.display = "none";
    }
}